package com.demomaster.quickcompat.sample;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.demomaster.quickcompat.drawable.QuickRoundDrawable;
import com.demomaster.quickcompat.service.ServiceHelper;
import com.demomaster.quickcompat.util.QuickThread;
import com.demomaster.quickcompat.util.StringUtil;
import com.demomaster.quickcompat.widget.QuickImageView;
import com.demomaster.quickcompat.widget.dialog.QuickDialog;
import com.demomaster.quickcompat.widget.layout.QuickSurroundLayout;
import com.demomaster.quickcompat.widget.layout.QuickSurroundWrapLayout;
import com.demomaster.quickcompat.widget.radiobutton.QuickRadioGroup;

public class TestActivity extends AppCompatActivity {
    Context mContext;
    View btn_window_request,btn_window_open;
    QuickSurroundLayout quickSurroundLayout;
    QuickSurroundLayout quickSurroundLayout2;
    QuickSurroundWrapLayout surroundLayout3;
    Button btn_06;
    Button button_05;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.layout_main2);
        QuickImageView quickImageView = findViewById(R.id.iv_test);
        if(quickImageView!=null)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //getResources().getDrawable(R.drawable.ic_launcher_background,getTheme());
            QuickRoundDrawable quickRoundDrawable = new QuickRoundDrawable(getResources().getDrawable(R.mipmap.ic_launcher,getTheme()), new float[]{30,30,10,10,50,50,50,50});
            quickImageView.setBackground(quickRoundDrawable);
        }
        StringUtil.isNotEmpty("");
        btn_window_request = findViewById(R.id.btn_window_request);
        if(btn_window_request!=null) {
            btn_window_request.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //悬浮窗权限
                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                    startActivity(intent);
                }
            });
        }
        btn_window_open = findViewById(R.id.btn_window_open);
        if(btn_window_open!=null) {
            btn_window_open.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!ServiceHelper.serverIsRunning(mContext, MyService.class.getName())) {
                        ServiceHelper.startService(mContext, MyService.class);
                    }
                }
            });
        }
        
        // 添加按钮样式演示页面的导航
        View btnButtonDemo = findViewById(R.id.btn_button_demo);
        if (btnButtonDemo != null) {
            btnButtonDemo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ButtonDemoActivity.class);
                    startActivity(intent);
                }
            });
        }
        //QdToast.show(mContext, "测试toast", Toast.LENGTH_SHORT);
        QuickThread.runOnUiThread(new Runnable() {
            @Override
            public void run() {

            }
        });
        QuickRadioGroup radioGroup = findViewById(R.id.radioGroup);
        if(radioGroup!=null) {
            radioGroup.setOnCheckedChangeListener(new QuickRadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(ViewGroup group, int checkedId) {
                    Toast.makeText(mContext, "checkedId:" + checkedId, Toast.LENGTH_SHORT).show();
                }
            });
        }
        View tv_click2 = findViewById(R.id.tv_click2);
        if(tv_click2!=null) {
            findViewById(R.id.tv_click2).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //Toast.makeText(mContext, "isClickable:"+isClickable, Toast.LENGTH_SHORT).show();
                }
            });
        }

        //Glide.with(mContext).load(R.mipmap.xiaoji).into((ImageView) findViewById(R.id.iv_test3));

        View iv_test3 = findViewById(R.id.iv_test3);
        if(iv_test3!=null) {
            iv_test3.setBackground(getResources().getDrawable(R.mipmap.ic_launcher));
            QuickThread.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    QuickThread.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mContext, "runOnSubThread:runOnUiThread", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }


        quickSurroundLayout = findViewById(R.id.surroundLayout);
        quickSurroundLayout.setOnClickListener(v -> {
            if (quickSurroundLayout.isShowing()) {
                quickSurroundLayout.stopAnimation();
            } else {
                quickSurroundLayout.startAnimation();
            }
        });
        quickSurroundLayout2 = findViewById(R.id.surroundLayout2);
        btn_06 = findViewById(R.id.btn_06);
        btn_06.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                QuickDialog quickDialog = new  QuickDialog.Builder(mContext).create();
                quickDialog.show();
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                //QdToast.show(mContext,"click");
                if (quickSurroundLayout2.isShowing()) {
                    quickSurroundLayout2.stopAnimation();
                } else {
                    quickSurroundLayout2.startAnimation();
                }
            }
        });

        surroundLayout3 = findViewById(R.id.surroundLayout3);
        button_05 = findViewById(R.id.button_05);
        button_05.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //QdToast.show(mContext,"click");
                if (surroundLayout3.isShowing()) {
                    surroundLayout3.stopAnimation();
                } else {
                    surroundLayout3.startAnimation();
                }
            }
        });
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();

    }
}
